package xyz.showbooks.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.dfm.util.JsonResult;
import xyz.dfm.util.UtilPagePojo;
import xyz.dfm.util.WebUtil;
import xyz.dfm.vo.PageResult;
import xyz.showbooks.mapper.CommentMapper;
import xyz.dfm.pojo.Comment;
import xyz.showbooks.service.CommentService;


import java.util.List;

/**
 * @author: Dsi
 * @date: 2022/2/18 18:51
 * @description:
 */@Service
public class CommentServiceImpl implements CommentService {
     @Autowired
     private CommentMapper commentMapper;
    @Override
    public PageResult findCommentByUserName(PageResult pageResult) {
        UtilPagePojo utilPagePojo = WebUtil.utilPagePojo(pageResult);
        List<Comment> commentByUserName = commentMapper.findCommentByUserName(utilPagePojo);
        return pageResult.setRows(commentByUserName);
    }

    @Override
    public JsonResult<Comment> updateStatus(Comment comment) {
            if (commentMapper.updateStatus(comment)==0){
                return JsonResult.build(201, "修改失败");
            };
            return JsonResult.build(200,"修改成功");
    }

    @Override
    public PageResult findCommentByStatus(PageResult pageResult) {
        UtilPagePojo utilPagePojo = WebUtil.utilPagePojo(pageResult);
        List<Comment> commentByStatus = commentMapper.findCommentByStatus(utilPagePojo);
        return pageResult.setRows(commentByStatus);
    }

    @Override
    public PageResult findCommentByBooksName(PageResult pageResult) {
        UtilPagePojo utilPagePojo = WebUtil.utilPagePojo(pageResult);
        List<Comment> commentByBooksName = commentMapper.findCommentByBooksName(utilPagePojo);
        return pageResult.setRows(commentByBooksName);
    }
}
